<template>
  <div id="">
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @cancel="$emit('cancel')"
      @confirm="confirm"
    />
  </div>
</template>

<script>
import { formatTime } from '@/filters/filters'
import { updateUserProfile } from '@/api/user.js'
export default {
  props: {
    value: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      minDate: new Date(1900, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.value)
    }
  },

  // 定义方法
  methods: {
    async confirm (val) {
      const time = formatTime(val)
      await updateUserProfile({
        birthday: time
      })
      this.$emit('cancel')
      this.$emit('input', time)
    }
  }
}
</script>

<style scoped lang="less"></style>
